package com.mcxx.modules.temporary.service.impl;

import com.mcxx.modules.temporary.service.TempRescueQueryExportService;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.filemanage.easypoi.util.ExportExcelService;
import com.mcxx.modules.filemanage.file.service.FileService;
import com.mcxx.modules.system.entity.TaskExportEntity;
import com.mcxx.modules.system.service.write.TaskExportWriteService;
import com.mcxx.modules.temporary.cancel.dto.TmpCancelExcelDTO;
import com.mcxx.modules.temporary.cancel.param.TmpCancelParam;
import com.mcxx.modules.temporary.cancel.service.read.TmpCancelReadService;
import com.mcxx.modules.temporary.family.dto.TempMemberExcelDto;
import com.mcxx.modules.temporary.family.dto.TmpFamilyExcelDTO;
import com.mcxx.modules.temporary.family.param.SalvationObjectParam;
import com.mcxx.modules.temporary.order.dto.TmpOrderStatement;
import com.mcxx.modules.temporary.order.service.read.TmpOrderReadService;
import com.mcxx.util.POIWriterExecl;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;


@Service
@TaTransactional
public class TempRescueQueryExportServiceImpl extends BaseService implements TempRescueQueryExportService {

    @Resource
    private ExportExcelService exportExcelService;
    @Autowired
    private TmpOrderReadService tmpOrderReadService;
    @Autowired
    private FileService fileService;
    @Autowired
    private TaskExportWriteService taskExportWriteService;
    @Autowired
    private TmpCancelReadService tmpCancelReadService;


    @Override
    public ExcelInfo exportExcel(String exportType, List<String> orderIdList, SalvationObjectParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        if("1".equals(exportType)){



            param.setMemberIdList(orderIdList);
            List<TempMemberExcelDto> list = tmpOrderReadService.exportRescueMemberList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(TempMemberExcelDto.class,list,"临时救助对象信息.xls",
                    "临时救助对象列表","临时救助对象列表",false,"");
        }else if("2".equals(exportType)){

            param.setOrderIdsList(orderIdList);
            List<TmpFamilyExcelDTO> list = tmpOrderReadService.exportRescueFamilyList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(TmpFamilyExcelDTO.class,list,"临时救助家庭信息.xls",
                    "临时救助家庭列表","临时救助家庭列表",false,"salaryMember");
        }

        return excelInfo;
    }

    @Override
    public ExcelInfo exportOrderDetail(String orderId,String areaName) {
        TmpOrderStatement tmpOrderStatement = tmpOrderReadService.selectOrderStatement(orderId);
        tmpOrderStatement.setArea(areaName);
        Workbook wb = null;
        try {
            wb =  POIWriterExecl.createOrderDetailExeclFile(tmpOrderStatement);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ExcelInfo excelInfo = exportExcelService.exportExcelByWorkBook(wb, "临时救助费用结算单.xls",tmpOrderStatement);
        return excelInfo;
    }

    @Override
    public ExcelInfo exportOrderCancel(TmpCancelParam param,UserAccountVo accountVo) {
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        List<TmpCancelExcelDTO> list = tmpCancelReadService.exportSalvationList(param);
        excelInfo = exportExcelService.exportOrgOpLogs(TmpCancelExcelDTO.class,list,"临时救助审核作废信息.xls",
                "临时救助审核作废列表","临时救助审核作废列表",false,"");

        return excelInfo;
    }
}
